﻿import kliment.display.MCC;
import kliment.math.Calc;
import mx.utils.Delegate;
/**
 * ...
 * @author	Kliment
 * @version 1.0.1
 */
class kliment.effect.SoundPoint {
	private var _target_mc:MovieClip;
	private var _space_mc:MovieClip;
	private var _sound:Sound;
	private var _radius:Number;
	
	public function SoundPoint(parent_mc:MovieClip, space_mc:MovieClip, radius:Number, sound_identifier:String) {
		_target_mc = parent_mc;
		_space_mc = space_mc;
		_radius = radius;
		_sound = new Sound(_target_mc);
		
		_init();
	}
	
	private function _init():Void {
		_target_mc.onEnterFrame = Delegate.create(this, _checkPosition);
	}
	
	private function _checkPosition():Void {
		var bounds:Object = MCC.getBounds(_space_mc);
		var center:Object = { x:(bounds.xMax + bounds.xMin) * .5, y:(bounds.yMax + bounds.yMin) * .5};
		var p:Object = { x:_target_mc._x, y:_target_mc._y };
		_target_mc._parent.localToGlobal(p);
		_space_mc.globalToLocal(p);
		
		var percent:Number = int((center.x - p.x) / _radius * 100);
		percent = Calc.inInterval(-100, 100, percent);
		_sound.getPan(percent);
		_sound.setVolume(100 - Math.abs(percent));
	}
}